<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateTableCustomerPlatformMappings extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('customer_platform_mappings', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('userId')->default(0)->comment('用户id');
            $table->string('name')->default('')->comment('用户昵称');
            $table->string('openId')->default('')->comment('用户openid');
            $table->string('unionid')->default('')->comment('用户unionid');
            $table->string('headImage')->default('')->comment('用户头像');
            $table->unsignedTinyInteger('platformId')->default(1)->comment(' 平台 ID  1:微信小程序 2:支付宝小程序 3:其他');
            $table->tinyInteger('isDeleted')->default(0)->comment("是否删除 0：未删除，1：已删除");
            $table->integer("createdAt")->default(0)->comment("创建时间");
            $table->integer("updatedAt")->default(0)->comment("修改时间");

            $table->index("createdAt", "idx_created_at");
            $table->index('unionid','idx_unionid');
            $table->index('userId','idx_userId');

            $table->collation = 'utf8mb4_general_ci';
        });

        $prefix = config('other.DB_PREFIX', '');
        \Illuminate\Support\Facades\DB::statement("ALTER TABLE `{$prefix}customer_platform_mappings` COMMENT = '平台关联表'"); //表注释
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('table_customer_platform_mappings');
    }
}
